﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlineManagement.Web.webs
{
    public partial class PigPenDelete : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            btnDelete.Click += new EventHandler(btnDelete_Click);
            btnCancel.Click += new EventHandler(btnCancel_Click);
            if (!Page.IsPostBack)
            {
                //string pigPenStr = Request.QueryString["pigPenId"] == null ? string.Empty : Request.QueryString["pigPenId"].ToString();
                //string customizeID = Request.QueryString["customizeID"] == null ? string.Empty : Request.QueryString["customizeID"].ToString();
                //Guid pigPen;
                //if (Guid.TryParse(pigPenStr, out pigPen) && !string.IsNullOrEmpty(customizeID))
                //{
                //    lbTitle.Text = "确定要删除" + customizeID + "号猪舍吗?";
                //}
                //else {
                //    lbTitle.Text = "请先选择要删除的猪舍号";
                //    btnDelete.Visible = false;
                //}
            }
        }
        void btnDelete_Click(object sender, EventArgs e)
        {
            string pigPenStr = Request.QueryString["pigPenId"] == null ? string.Empty : Request.QueryString["pigPenId"].ToString();
            string customizeID = Request.QueryString["customizeID"] == null ? string.Empty : Request.QueryString["customizeID"].ToString();
            Guid pigPen;
            if (Guid.TryParse(pigPenStr, out pigPen) && !string.IsNullOrEmpty(customizeID))
            {
                Delete(pigPen);
            }
        }

        void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("../webs/BasicSettings.aspx");
        }

      

        private void Delete(Guid pigPen) {
            try
            {
                BLL.Dal.PigPen bllPp = new BLL.Dal.PigPen();
                string message=string.Empty;
                bool result = bllPp.Delete(pigPen, out message);
                lbMsg.Text = message;
                
            }catch(Exception ex){
                
            }
        }
    }
}